<?php
	require_once 'bbs/include/common.inc.php';	
	require_once 'customer_config.php';	
	
	$uploaddir = "http://jingshi.youis.net/videofiles/";

	//得到视频分类
	$video_sort_sql = "select fid, name from topic_type where fup = 0 order by fid desc";
	$topic_type_query = $db->query($video_sort_sql);
	
	//播放视频页
	if($_GET['video_id'])
	{
		//如果没登陆
		if($discuz_uid == 0 || $discuz_uid == '')
		{
			echo "<script>location.href='/bbs/logging.php?action=login';</script>";
			exit;	
		}
		
		//判断是否有资格看视频
		$u_sql		= "select uid, groupid, extcredits1 from cdb_members where uid = '".$discuz_uid."'";
		$u_query	= $db->query($u_sql);
		$user_info	= $db->fetch_array($u_query);

		$user_integral	= $user_info['extcredits1'];
		$user_groupid	= $user_info['groupid'];
		
		//得到视频信息
		$sql		= "select * from video where id = '".trim($_GET['video_id'])."'";
		$query		= $db->query($sql);
		$video_info = $db->fetch_array($query);
	
		$video_file = $uploaddir.$video_info['video_name'];
		
		//需要分数
		$need_scores = $video_info['need_scores'];
	
		//用户不够分数并不在学员组中
		if($user_integral < $need_scores && $user_groupid != $user_config['groupid'])
		{
			$id = $_GET['id'];
			//echo "<script>alert('对不起！还不能查看此视频。（查看此视频需要$need_scores分，您目前积分为$user_integral分）'); location.href='/topic.php?id=$id';</script>";
			echo "<script>alert('您没有足够的积分，因此不能查看此视频。'); location.href='/topic.php?id=$id';</script>";
			exit;			
		}

		//查看用户是否已经看过该视频
		$u_v_sql		= "select vid from user_video where uid = '".$discuz_uid."'";
		$u_v_query		= $db->query($u_v_sql);
		$u_video_info	= $db->fetch_array($u_v_query);
	
		if($u_video_info['vid'] == '')
		{			
			//扣除分数
			$k_sql = "update cdb_members set extcredits1 = extcredits1 - ".$need_scores." where uid = '".$discuz_uid."'";
			$k_res = $db->query($k_sql);
			
			if($k_res)
			{
				$v_sql = "insert into user_video (uid, vid, insert_time) values ('".$discuz_uid."', '".$video_info['id']."', '".date('Y-m-d H:i:s', time())."')";
				$v_res = $db->query($v_sql);
			}
		}
		
		//查看视频要扣除的分数
		$deduct_scores = $video_info['deduct_scores'];

		//得到视频分类
		$s_sql		= "select fid, name from topic_type where fid = '".$video_info['sort']."'";
		$s_query	= $db->query($s_sql);
		$menu_info	= $db->fetch_array($s_query);
?>		
		<div>
			分类：<?php echo $menu_info['name'];?>
			视频文件名：<?php echo $video_info['title'];?>
		<div>
		<div id="vidwin" style='margin-top:80px'></div>
	
		<script type="text/javascript" src="./js/swfobject.js"></script>
		<script>
		function video_play(flv)
		{
			var s1 = new SWFObject("./flash/player.swf","ply","593","413","9","#FFFFFF");
			s1.addParam("allowfullscreen","true");
			s1.addParam("allowscriptaccess","always");
			s1.addParam("flashvars","file="+flv+"&image=./images/logo.png");
			//s1.addParam("flashvars","file="+flv+"&image=./images/logo.png&autostart=true");// 添加flv视频,初始图片
			s1.write("vidwin");
		}
		
		jQuery(document).ready(function(){
			var flv = "<?php echo $video_file?>";
			video_play(flv);
		})
		</script>
		
<?php }else{?>
	
	
	<table border="0" width="98%" align="center">
		<?php while($sort_menu_info = $db->fetch_array($topic_type_query)) { ?>
		<tr>
			<td colspan="3"><a statisic="tomore" target="_blank" href="#"><b><?php echo $sort_menu_info['name'];?></b></a></td>
			<td><span class="pding">|</span>&nbsp;&nbsp;<a target="_blank" href="xt_video_list.php?&id=<?php echo $id;?>&fid=<?php echo $sort_menu_info['fid'];?>"><b>更多</b><span class="few">&gt;&gt;</span></a></td>
		</tr>
		<tr>
		
			<?php 
				$sql = "select * from video where sort = '".$sort_menu_info['fid']."'";
				$query = $db->query($sql);	
				$c = 0;
				while($video_info = $db->fetch_array($query)) { 
					//显示4个视频
					if($c == 4)
					{
						 break;
					}
					$c++;
			?>
				<td>
					<table border="0">
						<tr>
							<td>
				<a statisic="toplay" title="<?php echo $video_info['title']?>" target="_blank" href="?id=<?php echo $id;?>&video_id=<?php echo $video_info['id']; ?>" class="hd"><img width="114" height="152" src="./images/lv2imagelinks/01.png"><span class="play"></span></a>
							</td>
						</tr>
						<tr><td><a statisic="toplay" target="_blank" href="?id=<?php echo $id;?>&video_id=<?php echo $video_info['id']; ?>" title="<?php echo $video_info['title']?>" class="wbr"><?php echo $video_info['title']?></a></td></tr>
						<tr><td align="center"><?php 
			        				if($video_info['deduct_scores'] == 0){ 
										echo '<div>不需要积分</div>';
									}else{
										echo '<div>所需积分：'.$video_info['deduct_scores'].'</div>';
									}
			        			?></td></tr>
					</table>
				
				
				</td>
				
			<?php } ?>	
			
		</tr>
		<?php } ?>	
	</table>
<?php } ?>